package org.qiancizhan.Controller;

import org.qiancizhan.Mapper.UserMapper;
import org.qiancizhan.Model.DTO.LoginDTO;
import org.qiancizhan.Model.POJO.UserPOJO;
import org.qiancizhan.Utils.MD5CryptoUtil;

public class UserController {
    private final UserMapper userMapper = new UserMapper();

    public UserPOJO login(LoginDTO userData) {
        UserPOJO map = userMapper.getUser(userData.getUsername());
        return map == null ? null : (MD5CryptoUtil.verify(userData.getPassword(), map.getPassword()) ? map : null);
    }

    public boolean register(LoginDTO userData) {
        UserPOJO map = userMapper.getUser(userData.getUsername());
        return map != null ? false : userMapper.addUser(userData);
    }
}
